﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAO;
using DTO;
using Banking;
namespace Banking.Nhân_viên
{
    public partial class DanhSachKhachHang : UserControl
    {
        TypeDemo _type;
        public DanhSachKhachHang(TypeDemo type)
        {
            InitializeComponent();
            _type = type;
        }

        private void DanhSachKhachHang_Load(object sender, EventArgs e)
        {
            DataTable dt = NhanVienDAO.DanhSachKH();
            LoadDSKH(dt);
            LoadTruSo();
            LoadLoaiKH();
        }
        private void LoadDSKH(DataTable dt)
        {
            dgvDanhSachKH.DataSource = dt;
            dgvDanhSachKH.Columns["MaLoaiKH"].Visible = false;
            dgvDanhSachKH.Columns["MaTruSo"].Visible = false;
        }
        private void LoadTruSo()
        {
            DataTable dt = NhanVienDAO.DSTruSo();
            cmbTruSo.DataSource = dt;
            cmbTruSo.DisplayMembers = "Ten";
            cmbTruSo.ValueMember = "MaTruSo";
        }
        private void LoadLoaiKH()
        {
            DataTable dt = NhanVienDAO.DSLoaiKH();
            cmbLoaiKH.DataSource = dt;
            cmbLoaiKH.DisplayMembers = "TenLoai";
            cmbLoaiKH.ValueMember = "MaLoai";
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            int t=0;
            KhachHang kh = new KhachHang();
            int.TryParse(txtMaKH.Text, out t);
            kh.MaKH = t;
            kh.Ten = txtHoTen.Text;
            kh.DiaChi = txtDiaChi.Text;
            kh.MaTruSo = int.Parse(cmbTruSo.SelectedValue.ToString());
            kh.MaLoaiKH = int.Parse(cmbLoaiKH.SelectedValue.ToString());
            DataTable dt = NhanVienDAO.TimKiemKH(kh);
            LoadDSKH(dt);
        }

        private void btnChiTiet_Click(object sender, EventArgs e)
        {
            if (dgvDanhSachKH.SelectedRows.Count == 1)
            {
                int maKH = int.Parse(dgvDanhSachKH.SelectedRows[0].Cells["MaKH"].Value.ToString());
                ChiTietKH frm = new ChiTietKH(maKH);
                frm.ShowDialog();
            }
        }

        private void btnTKThe_Click(object sender, EventArgs e)
        {
            if (dgvDanhSachKH.SelectedRows.Count == 1)
            {
                int maKH = int.Parse(dgvDanhSachKH.SelectedRows[0].Cells["MaKH"].Value.ToString());
                frmTaoTKThe frm = new frmTaoTKThe(maKH);
                frm.ShowDialog();

            }

        }

        private void btnTTTK_Click(object sender, EventArgs e)
        {
            if (dgvDanhSachKH.SelectedRows.Count == 1)
            {
                int maKH = int.Parse(dgvDanhSachKH.SelectedRows[0].Cells["MaKH"].Value.ToString());
                ThongTinTaiKhoanThe frm = new ThongTinTaiKhoanThe(maKH, _type);
                frm.ShowDialog();
            }
        }

        private void btnTKTK_Click(object sender, EventArgs e)
        {
            if (dgvDanhSachKH.SelectedRows.Count == 1)
            {
                int maKH = int.Parse(dgvDanhSachKH.SelectedRows[0].Cells["MaKH"].Value.ToString());
                frmTKTietKiem frm = new frmTKTietKiem(maKH,_type);
                frm.ShowDialog();
            }
        }

        private void btnTaoTKTK_Click(object sender, EventArgs e)
        {
            if (dgvDanhSachKH.SelectedRows.Count == 1)
            {
                int maKH = int.Parse(dgvDanhSachKH.SelectedRows[0].Cells["MaKH"].Value.ToString());
                frmChiTietTKTK frm = new frmChiTietTKTK(maKH, 0, 0, _type);
                frm.ShowDialog();
            }
        }


     }
}
